{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 仿生蜘蛛基本运动控制\n",
    "\n",
    "## 硬件准备\n",
    "\n",
    "材料：\n",
    "\n",
    "I模块*2、T模块*4、万方向轮*2\n",
    "\n",
    "\n",
    "\n",
    "## 硬件连接\n",
    "\n",
    "连接五自由度操作臂\n",
    "\n",
    "\n",
    "\n",
    "## 关节配置\n",
    "\n",
    "将硬件连接的关节ID次序更新到配置文件中\n",
    "\n",
    "\n",
    "\n",
    "配置完后启动设备\n",
    "\n",
    "\n",
    "# 代码说明\n",
    "\n",
    "### 导入库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!/usr/bin/python\n",
    "# -*- coding: UTF-8 -*-\n",
    "import sys;\n",
    "sys.path.append(\"..\")\n",
    "sys.path.append(\"../../\")\n",
    "from lib.BwRobotLib import BwRobotLib\n",
    "from RobotSpider.SpiderRobot import SpiderRobot\n",
    "import keyboard\n",
    "import time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 声明库对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#声明库对象\n",
    "robotlib = BwRobotLib()\n",
    "spiderRobot = SpiderRobot(robotlib)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 连接设备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "连接成功\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#连接机器人设备\n",
    "robotlib.connectRobot(\"192.168.1.107\",55000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 配置并初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "读取ID配置文件:\n",
      "L1:30,31\n",
      "\n",
      "L3:32,33\n",
      "\n",
      "R1:34,35\n",
      "\n",
      "R2:36,37\n",
      "\n",
      "机器人初始化设置成功\n"
     ]
    }
   ],
   "source": [
    "#加载配置（兼容VS项目启动方式及文件直接启动方式）\n",
    "import os,inspect\n",
    "fileName = inspect.getframeinfo(inspect.currentframe()).filename\n",
    "folderPath     = os.path.dirname(os.path.abspath(fileName))\n",
    "cfile=folderPath+\"/config.txt\"\n",
    "robotlib.loadConfig(cfile)\n",
    "\n",
    "#配置ID\n",
    "spiderRobot.bindIds(robotlib.module_ids)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 主程序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter any key to initialize....\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter any key to run ....\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "向前走\n",
      "向前走\n",
      "向前走\n",
      "向后走\n",
      "向后走\n",
      "向后走\n",
      "向左转向\n",
      "向左转向\n",
      "向左转向\n",
      "向右转向\n",
      "向右转向\n",
      "向右转向\n",
      "跳舞\n",
      "跳舞\n",
      "跳舞\n",
      "打招呼\n",
      "打招呼\n",
      "打招呼\n",
      "蹲下起立\n",
      "蹲下起立\n",
      "蹲下起立\n",
      "俯卧撑\n",
      "俯卧撑\n",
      "俯卧撑\n",
      "单手俯卧撑\n",
      "单手俯卧撑\n",
      "单手俯卧撑\n",
      "摇尾巴\n",
      "摇尾巴\n",
      "摇尾巴\n",
      "战斗\n",
      "战斗\n",
      "战斗\n",
      "扭动身体\n",
      "扭动身体\n",
      "扭动身体\n",
      "Enter any key to run ....\n"
     ]
    }
   ],
   "source": [
    "print(\"Enter any key to initialize....\")\n",
    "input(\"\")\n",
    "spiderRobot.quickInit()\n",
    "while(1):\n",
    "  print(\"Enter any key to run ....\")\n",
    "  input(\"\")\n",
    "  spiderRobot.runDemo()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
